<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>login</title>
		<link href="../../css/mui.min.css" rel="stylesheet" type="text/css" />
		<link href="../../css/app.css" rel="stylesheet" type="text/css" />
		<style type="text/css">
			.mui-input-group .mui-input-row:after {
				position: absolute;
				height: 1px;
			}
			
			.logo {
				text-align: center;
				margin: 10px auto;
				margin-top: 20%;
			}
			
			.logo img {
				width: 60%;
			}
			
			.mui-content {
				background: none;
			}
			
			.mui-active {
				color: #0072dc;
			}
			
			.mui-btn-positive {
				border: 1px solid #0072dc;
				background-color: #0072dc;
			}
			
			.mui-btn-block {
				padding: 10px;
				margin: 20px auto 40px auto;
				clear: both;
				overflow: hidden;
			}
			
			.mui-card {
				padding: 20px 20px 50px 10px;
			}
			
			.input {
				padding: 5px;
			}
			
			input {
				color: #333;
			}
			/*.mui-btn-positive:enabled:active {
	    color: #fff;
	    border: 1px solid #5CC4D8;
	    background-color: #5CC4D8;
	}*/
		</style>
	</head>

	<body>
		<div class="mui-content">
			<div class="mui-active">
				<div class="logo">
					<img src="../../Images/login_title.png" />
				</div>
				<div class="mui-card">
					<form class="mui-input-group" style="margin-top: 0px;">
						<div class="mui-input-row">
							<label>用户名</label>
							<input type="text" class="input" id="username" placeholder="用户名" value="13333333333" />
						</div>
						<div class="mui-input-row">
							<label>密码</label>
							<input type="password" class="input" id="password" placeholder="密码" value="123456" />
						</div>
						<div class="mui-button-row">
							<button type="button" id="login-post" class="mui-btn mui-btn-positive mui-btn-block login-btn">登录</button>
						</div>
					</form>
					<div class="mui-row" style="margin-top: 50px;">
						<div class="mui-col-xs-6 mui-text-left">
							<a href="#" id="btnRepReg">注册新用户</a>
						</div>
						<div class="mui-col-xs-6 mui-text-right">
							<a href="#" id="btnForget">忘记密码？</a>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/mui-extend.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/app.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			var relogin = false;
			mui.plusReady(function() {
				var current = plus.webview.currentWebview();
				var $ = mui;
				mui.init({
					swipeBack: false
				});
				mui.back = function() {
					plus.runtime.quit();
				};
				var canFire = false;
				var mainPage = plus.webview.create('index.html', 'index')
				mainPage.addEventListener('loaded', function() {
					canFire = true;
				});
				var toMain = function(directToMain) {
					plus.nativeUI.showWaiting();
					doShow();

					function doShow() {
						if(canFire) {
							//							plus.nativeUI.closeWaiting();
//							console.log("fire mainPage show");
							$.fire(mainPage, 'show', directToMain ? {
								closeSplash: true
							} : null);
						} else {
							setTimeout(doShow, 100);
						}
					}
				};

				function goIndex() {
					var uid = persistent.uid();
					if(!tool.isEmptyVal(uid)) {
//						console.log("直接去首页！！！");
						toMain(true);
					} else {
						plus.navigator.closeSplashscreen();
					}
				}

				goIndex();

				mui('body').on('tap', '#login-post', function(data) {
					var username = document.getElementById("username").value;
					var password = document.getElementById("password").value;
					if(!username) {
						plus.nativeUI.toast('请填写用户名');
						return;
					}
					if(!password) {
						plus.nativeUI.toast('请填写密码');
					}
					user.login(username, password, function() {
						if (!relogin) {
							toMain();
						} else {
							mui.fire(mainPage, 'relogin');
						}
					}, false);
				});
				app.on(document, 'relogin', function() {
					relogin = true;
					// 重新登录，无需检测更新，记住用户名
					var userName = cache('lastUser');
					if(userName) {
						document.getElementById("username").value = userName;
					}
					document.getElementById("password").value = '';
					showPage(current);
				});
				
				
				// 忘记密码
				document.getElementById("btnForget").addEventListener('tap',function () {
					openPage('../index/findPassword.html','findPassword');
				});
				// 注册新用户
				document.getElementById("btnRepReg").addEventListener('tap',function () {
					openPage('../index/register.html','register');
				});
			});
		</script>
	</body>

</html>